package com.fyzk.activity.user;

import java.util.ArrayList;
import java.util.List;

import android.util.Log;

import com.fyzk.bean.model.HaoMa;
import com.fyzk.utils.LotteryIDUtils;

public class HaoMaSplit {
	
	public static boolean isFuShi;
	
	public static List<HaoMa> getHM(String haoMaString, String id, String prizeContent){
		Log.e("haoMa..", "==============>>>>     "+id);
		if (id.equals(LotteryIDUtils.SSQ_LOTTERY_ID_INT+"")||id.equals(LotteryIDUtils.DLT_LOTTERY_ID_INT+"")) {
			return getSsqHaoMas(haoMaString, prizeContent);
		}else if (id.equals(LotteryIDUtils.PL5_LOTTERY_ID_INT+"")) {
			return getPL5HaoMas(haoMaString, prizeContent);
		}else{
			return getPL5HaoMas(haoMaString, prizeContent);
		}
		
	}
	
	/**
	 * ssq拆分号码串
	 */
	private static List<HaoMa> getSsqHaoMas(String haoMaString, String prizeContent) {
		List<HaoMa> haoMas = new ArrayList<HaoMa>();
		Log.e("haoMa..", "==============     "+haoMaString);
		if (!haoMaString.contains("^")) {
			return haoMas;
		}
		String[] haos = haoMaString.split("\\^");

		for (int a = 0; a < haos.length; a++) {
			String haoMa = haos[a];
			String hongString = "";
			String lanString = "";
			String danTuoString = "";

			if (haoMa.contains("|")) {
				String[] h = haoMa.split("\\|");
				if (h[0].contains("#")) {
					String[] hd = h[0].split("\\#");
					hongString = hd[0];
					danTuoString = hd[1];
				} else {
					hongString = h[0];
				}
				lanString = h[1];
			} 

			if (hongString != null && !hongString.toString().equals("")) {
				if (hongString.contains("-")) {
					hongString = hongString.split("-")[1];
				}
				if (hongString.contains(",")) {
					
					String[] hongStrings = hongString.split(",");
					if (hongStrings.length > 6) {
						isFuShi = true;
					}
					for (int i = 0; i < hongStrings.length; i++) {
						HaoMa haoMa1 = new HaoMa(hongStrings[i],
								HaoMa.TYPE_HONG, isPrizeNum(prizeContent, hongStrings[i], false));
						haoMas.add(haoMa1);
					}
				}else{
					HaoMa haoMa1 = new HaoMa(hongString,
							HaoMa.TYPE_HONG, isPrizeNum(prizeContent, hongString, false));
					haoMas.add(haoMa1);
				}

			}

			if (danTuoString != null && !danTuoString.toString().equals("")) {
				if (danTuoString.contains(",")) {
					
					String[] huangStrings = danTuoString.split(",");
					for (int i = 0; i < huangStrings.length; i++) {
						HaoMa haoMa1 = new HaoMa(huangStrings[i], HaoMa.TYPE_HUANG,
								isPrizeNum(prizeContent, huangStrings[i], false));
						haoMas.add(haoMa1);
					}
				}else{
					HaoMa haoMa1 = new HaoMa(danTuoString, HaoMa.TYPE_HUANG,
							isPrizeNum(prizeContent, danTuoString, false));
					haoMas.add(haoMa1);
				}
			}

			if (lanString != null && !lanString.toString().equals("")) {
				if (lanString.contains(",")) {
					isFuShi = true;
					String[] lanStrings = lanString.split(",");
					for (int i = 0; i < lanStrings.length; i++) {
						HaoMa haoMa1 = new HaoMa(lanStrings[i], HaoMa.TYPE_LAN,
								isPrizeNum(prizeContent, lanStrings[i], true));
						haoMas.add(haoMa1);
					}
				}else{
					HaoMa haoMa1 = new HaoMa(lanString, HaoMa.TYPE_LAN,
							isPrizeNum(prizeContent, lanString, true));
					haoMas.add(haoMa1);
				}
			}

			for (int i = 0; i < haoMas.size() % 7; i++) {
				HaoMa haoMa1 = new HaoMa("", HaoMa.TYPE_FEI, false);
				haoMas.add(haoMa1);
			}
			for (int i = 0; i < 7; i++) {
				HaoMa haoMa1 = new HaoMa("", HaoMa.TYPE_FEI1, false);
				haoMas.add(haoMa1);
			}
		}

		return haoMas;
	}
	
	/**
	 * pl5拆分号码串
	 */
	private static List<HaoMa> getPL5HaoMas(String haoMaString, String prizeContent) {
		List<HaoMa> haoMas = new ArrayList<HaoMa>();
		Log.e("haoMa..", "--------------     "+haoMaString);
		haoMaString = haoMaString.substring(0, haoMaString.length()-1);
		String [] haos = haoMaString.split("-");
		String wanFa = haos[0];
		String content = haos[1];
		if (wanFa.equals(LotteryIDUtils.PL5_LOTTERY_COMMON_DAN_ID_INT+"")) {//单式   00,02,03,04,05
			String[] h = content.split(",");
			for (int i = 0; i < h.length; i++) {
				HaoMa haoMa1 = new HaoMa(""+h[i], HaoMa.TYPE_HONG, false);
				haoMas.add(haoMa1);
			}
		}else{// 复式 09,08|09,07|09,04,03|09,05,04|09,07,06
			isFuShi = true;
			String[] weis = content.split("\\|");
			for (int i = 0; i < weis.length; i++) {
				String wei = weis[i];
				if (wei.contains(",")) {
					String[] w = wei.split(",");
					for (int j = 0; j < w.length; j++) {
						HaoMa haoMa1 = new HaoMa(""+w[j], HaoMa.TYPE_HONG, isPrizeNum(prizeContent, w[j], false));
						if (j == 0) {
							haoMa1.setBiaoJi(HaoMa.BIAOJI_TOU);
						}else if (j == w.length-1) {
							haoMa1.setBiaoJi(HaoMa.BIAOJI_WEI);
						}else{
							haoMa1.setBiaoJi(HaoMa.BIAOJI_ZHONG);
						}
						
						haoMas.add(haoMa1);
					}
					
				}else{
					HaoMa haoMa1 = new HaoMa(""+wei, HaoMa.TYPE_HONG, false);
					haoMa1.setBiaoJi(HaoMa.BIAOJI_TOUANDWEI);
					haoMas.add(haoMa1);
				}
				
			}
		}
		
		for (int i = 0; i < haoMas.size() % 7; i++) {
			HaoMa haoMa1 = new HaoMa("", HaoMa.TYPE_FEI, false);
			haoMas.add(haoMa1);
		}
		for (int i = 0; i < 7; i++) {
			HaoMa haoMa1 = new HaoMa("", HaoMa.TYPE_FEI1, false);
			haoMas.add(haoMa1);
		}

		return haoMas;
	}
	
	/**
	 * 判断开奖号码
	 * @param prizeContent	开奖号码内容
	 * @param num	要判断的号码
	 * @param isLan	是不是蓝球
	 * @return
	 */
	private static boolean isPrizeNum(String prizeContent,String num, boolean isLan){
		return false;
//		if (prizeContent.contains("|")) {//双色球、大乐透开奖号码
//			String hongNum = prizeContent.split("\\|")[0];
//			String lanNum = prizeContent.split("\\|")[1];
//			if (isLan) {//蓝球
//				return lanNum.contains(num);
//			}else{
//				return hongNum.contains(num);
//			}
//		}else{//排列3、5。。开奖号码
//			return prizeContent.contains(num);//不确定  是否区分号码位置
//		}
	}
}
